#include "stdafx.h"
#include "CardHelper.h"

namespace Librarian
{
	namespace Data
	{
		CardEntity^ CardHelper::ReadCard(DataRow^ row)
		{
			CardEntity^ entity = gcnew CardEntity();
			entity->CardNo = Convert::ToString(row["card_no"]);
			entity->Name = Convert::ToString(row["name"]);
			entity->Department = Convert::ToString(row["department"]);
			entity->CardType = Convert::ToChar(row["card_type"]);
			return entity;
		}

		CardEntity^ CardHelper::ReadCard(DataTable^ table)
		{
			if (table->Rows->Count == 0)
			{
				return gcnew CardEntity();
			}
			return ReadCard(table->Rows[0]);
		}

		array<CardEntity^>^ CardHelper::Reads(DataTable^ table)
		{
			List<CardEntity^>^ entities = gcnew List<CardEntity^>();
			for(int i = 0; i< table->Rows->Count; i++)
			{
				DataRow^ row = table->Rows[i];
				entities->Add(ReadCard(row));
			}
			return entities->ToArray();
		}
	}
}